{extend name="layout"}
{block name="title"}编辑增员{/block}
{block name="body"}
<div class="content">
    <form class="mainForm" data-auto="false"  data-callback="submitCallback">
        {if $increase.status eq 3}
        <div class="error-info">
            <p><span class="iconfont icon-gantanhao-quan"></span> {$increase.feedback|default=""}</p>
        </div>
        {/if}

        <div class="item-box">
            <div class="item-title">
                员工信息
            </div>
            <div class="item-form">
                <div class="item-row">
                    <span class="label-required-prev">员工姓名：</span>
                    <div>
                        <input type="text" name="name" required placeholder="请输入姓名" autocomplete="off" value="{$increase.name|default=""}">
                    </div>
                </div>
                <div class="item-row">
                    <span>身份证号：</span>
                    <div>
                        <input type="text" name="id_number" required placeholder="请输入身份证号" autocomplete="off" value="{$increase.id_number|default=""}">
                    </div>
                </div>
                <div class="item-row">
                    <span>电话号码：</span>
                    <div>
                        <input type="number" name="mobile" required placeholder="请输入电话号码" autocomplete="off" value="{$increase.mobile|default=""}">
                    </div>
                </div>
                <div class="item-row">
                    <span>服务账期：</span>
                    <div>

                        <input readonly  name="start_date" required placeholder="请输选择起始日期" autocomplete="off" value="{$increase.start_date|default=""}">
                    </div>
                </div>
                <div class="item-row">
                    <span>月发工资：</span>
                    <div>
                        <input type="number" name="wage" required placeholder="请输选择月发工资" autocomplete="off" value="{$increase.wage|default=""}">
                    </div>
                </div>
                <div class="item-row">
                    <span>托管档案：</span>
                    <div>
                        <select name="archives" required>
                            <option value="1" {if $increase.archives eq 1}selected{/if}>是</option>
                            <option value="0" {if $increase.archives eq 0}selected{/if}>否</option>
                        </select>
                    </div>
                </div>

            </div>
        </div>
        <div class="item-box insurance_type">
            <div class="item-title">
                保险信息
            </div>
            <div class="item-form insurance-box {if ($increase_insurance.0.status eq 0) or ($insurances.0.status eq 0)}notChange{/if}" data-insurance="1" >
            <div class="item-form-title">
                <span class="label-required-prev">养老保险</span>
                <div>
                    <input  class="weui-switch" type="checkbox" name="insurance_status[1]" {if $increase_insurance.0.status neq 0} checked {/if}{if $insurances.0.status eq 0} disabled {/if}>
                </div>
            </div>
            <div class="item-row">
                <span class="label-required-prev">起始日期：</span>
                <div>
                    <input readonly class="startDate"   name="insurance_start_date[1]" placeholder="请选择"  value="{$increase_insurance.0.start_date|default=""}"  {if ($increase_insurance.0.status eq 0) or ($insurances.0.status eq 0)} disabled {else/} required{/if}>
                </div>
            </div>
            <div class="item-row">
                <span class="label-required-prev">社保工资：</span>
                <div>
                    <input type="hidden" name="insurance_area[1]" id=""  value="{$insurances.0.area|default=0}" />
                    <input type="text" name="insurance_wage[1]" lay-verify="required" value="{$increase_insurance.0.wage|default=""}"  placeholder="请输入" autocomplete="off" class="layui-input" {if ($increase_insurance.0.status eq 0) or ($insurances.0.status eq 0)} disabled {else/} required {/if}>
                </div>
            </div>
            <div class="item-row">
                <span class="label-required-prev">公司基数：</span>
                <div>
                    <input type="text" title=" " name="company_base[1]" value="{$increase_insurance.0.company_base|default=""}" readonly   lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="item-row">
                <span class="label-required-prev">个人基数：</span>
                <div>
                    <input type="text" title=" " name="personal_base[1]" value="{$increase_insurance.0.personal_base|default=""}" readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>

        </div>
        <div class="item-form insurance-box {if ($increase_insurance.1.status eq 0) or ($insurances.1.status eq 0)}notChange{/if}" data-insurance="2" >
        <div class="item-form-title">
            <span class="label-required-prev">工伤保险</span>
            <div>

                <input class="weui-switch" type="checkbox" name="insurance_status[2]"  {if $increase_insurance.1.status neq 0} checked {/if}{if $insurances.1.status eq 0} disabled{/if}>

            </div>
        </div>
        <div class="item-row">
            <span class="label-required-prev">起始日期：</span>
            <div>
                <input readonly class="startDate" placeholder="请选择" name="insurance_start_date[2]"  value="{$increase_insurance.1.start_date|default=""}"  {if ($increase_insurance.1.status eq 0) or ($insurances.1.status eq 0)} disabled {else/} required {/if}>
            </div>
        </div>
        <div class="item-row">
            <span class="label-required-prev">社保工资：</span>
            <div>
                <input type="hidden" name="insurance_area[2]" id=""  value="{$insurances.1.area|default=0}" />
                <input  type="text" name="insurance_wage[2]"  lay-verify="required" value="{$increase_insurance.1.wage|default=""}"   placeholder="请输入" autocomplete="off" class="layui-input" {if ($increase_insurance.1.status eq 0) or ($insurances.1.status eq 0)} disabled {else/} required {/if}>
            </div>
        </div>
        <div class="item-row">
            <span class="label-required-prev">公司基数：</span>
            <div>
                <input type="text" title=" " name="company_base[2]" readonly value="{$increase_insurance.1.company_base|default=""}"  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="item-row">
            <span class="label-required-prev">个人基数：</span>
            <div>
                <input type="text" title=" " name="personal_base[2]" readonly value="{$increase_insurance.1.personal_base|default=""}"  lay-verify="required" placeholder=" " autocomplete="off" class="layui-input">
            </div>
        </div>

</div>
<div class="item-form insurance-box {if ($increase_insurance.2.status eq 0) or ($insurances.2.status eq 0)}notChange{/if}" data-insurance="3" >
<div class="item-form-title">
    <span class="label-required-prev">失业保险</span>
    <div>
        <input class="weui-switch" type="checkbox"  name="insurance_status[3]"  {if $increase_insurance.2.status neq 0} checked {/if}{if $insurances.2.status eq 0} disabled{/if}>

    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">起始日期：</span>
    <div>
        <input readonly class="startDate"   placeholder="请选择" name="insurance_start_date[3]" value="{$increase_insurance.2.start_date|default=""}"  {if ($increase_insurance.2.status eq 0) or ($insurances.2.status eq 0)} disabled {else/} required {/if}>
    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">社保工资：</span>
    <div>
        <input type="hidden" name="insurance_area[3]" id=""  value="{$insurances.2.area|default=0}" />
        <input type="text" name="insurance_wage[3]"  lay-verify="required" value="{$increase_insurance.2.wage|default=""}" placeholder="请输入" autocomplete="off" class="layui-input" {if ($increase_insurance.2.status eq 0) or ($insurances.2.status eq 0)} disabled {else/} required {/if}>
    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">公司基数：</span>
    <div>
        <input type="text" title=" " name="company_base[3]" readonly value="{$increase_insurance.2.company_base|default=""}"  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">个人基数：</span>
    <div>
        <input type="text" title=" " name="personal_base[3]" readonly value="{$increase_insurance.2.personal_base|default=""}"  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
</div>

</div >
<div class="item-form insurance-box {if ($increase_insurance.3.status eq 0) or ($insurances.3.status eq 0)}notChange{/if}" data-insurance="4" >
<div class="item-form-title">
    <span class="label-required-prev">医疗保险</span>
    <div>
        <input class="weui-switch" type="checkbox"  name="insurance_status[4]"   {if $increase_insurance.3.status neq 0} checked {/if}{if $insurances.3.status eq 0} disabled {/if}>

    </div>
</div>
<div class="item-row" >
    <span class="label-required-prev">起始日期：</span>
    <div>
        <input readonly class="startDate"   placeholder="请选择" name="insurance_start_date[4]" value="{$increase_insurance.3.start_date|default=""}"  {if ($increase_insurance.3.status eq 0) or ($insurances.3.status eq 0)} disabled {else/} required  {/if}>
    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">社保工资：</span>
    <div>
        <input type="hidden" name="insurance_area[4]" id=""  value="{$insurances.3.area|default=0}" />
        <input type="text" name="insurance_wage[4]" value="{$increase_insurance.3.wage|default=""}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" {if ($increase_insurance.3.status eq 0) or ($insurances.3.status eq 0)} disabled {else/} required {/if}>
    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">公司基数：</span>
    <div>
        <input type="text" title=" " name="company_base[4]" readonly value="{$increase_insurance.3.company_base|default=""}"   lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">个人基数：</span>
    <div>
        <input type="text" title=" " name="personal_base[4]" readonly value="{$increase_insurance.3.personal_base|default=""}"  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
</div>

</div>
<div class="item-form insurance-box {if ($increase_insurance.4.status eq 0) or ($insurances.4.status eq 0)}notChange{/if}" data-insurance="5" >
<div class="item-form-title">
    <span class="label-required-prev">住房公积金</span>
    <div>
        <input class="weui-switch" type="checkbox"  name="insurance_status[5]"   {if $increase_insurance.4.status neq 0} checked {/if}{if $insurances.4.status eq 0} disabled {/if}>

    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">起始日期：</span>
    <div>
        <input readonly class="startDate"   name="insurance_start_date[5]" placeholder="请选择"  value="{$increase_insurance.4.start_date|default=""}"  {if ($increase_insurance.4.status eq 0) or ($insurances.4.status eq 0)} disabled {else/} required {/if}>
    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">社保工资：</span>
    <div>
        <input type="hidden" name="insurance_area[5]" id=""  value="{$insurances.4.area|default=0}" />
        <input type="text" name="insurance_wage[5]"  lay-verify="required" value="{$increase_insurance.4.wage|default=""}" placeholder="请输入" autocomplete="off" class="layui-input" {if ($increase_insurance.4.status eq 0) or ($insurances.4.status eq 0)} disabled {else/} required {/if}>
    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">公司基数：</span>
    <div>
        <input type="text" title=" " name="company_base[5]" readonly value="{$increase_insurance.4.company_base|default=""}"  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
</div>
<div class="item-row">
    <span class="label-required-prev">个人基数：</span>
    <div>
        <input type="text" title=" " name="personal_base[5]" readonly value="{$increase_insurance.4.personal_base|default=""}"  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
</div>

</div>




</div>
<div class="button-box">
	<input type="hidden" name="id" id="id" value="{$increase.id|default=0}" />
    <a class="add-updata" onclick="formSubmit()">提交审核</a>

</div>
</form>

</div>


{/block}
{block name="script"}
<!--<script>-->
<!--	$(function (){-->
<!--		var docmHeight= document.documentElement.clientHeight ||document.body.clientHeight,-->
<!--			showHeight= document.documentElement.clientHeight ||document.body.clientHeight-->
<!--		// var Height = $('body').height();-->
<!--		// console.log(docmHeight -80,showHeight)-->
<!--		// 回到顶部-->
<!--		$(window).resize(function () {-->
<!--			// 回到顶部-->
<!--			showHeight= document.documentElement.clientHeight ||document.body.clientHeight-->
<!--			// console.log(showHeight)-->
<!--			if((docmHeight - 100)> showHeight){-->
<!--				//隐藏-->
<!--				$(".button-box").hide()-->
<!--			}else{-->
<!--				//显示-->
<!--				$(".button-box").show()-->
<!--			}-->
<!--		});-->
<!--	})-->
<!--</script>-->
<script>
	$(function () {
		// $(".startDate").calendar({dateFormat: 'yyyy-mm-dd',});

		// $("[name='start_date']").change(function(){
		// 	var val =$(this).val();
		// 	$(".insurance_type div[class!='notChange']").each(function(){
		// 		$(this).find("[name^='insurance_start_date']").val(val)
		// 		// $(this).find("[name='insurance_start_date[4]']").val(getNextMonth(val))
		// 	})
		//
		// 	// $(".insurance_type tbody tr[class!='notChange']").find("[name^='insurance_start_date']").val($(this).val())
		// 	// form.render();
		// })
		var startDateVal = getStartDate()
		$('.startDate').each(function(){
			laydate.render({
				elem: this,       //使用this指向当前元素,不能使用class名, 否则只有第一个有效
				format: 'yyyy-MM-dd',
				type:'date',
				max:startDateVal[2],
				trigger: 'click',
				btns: ['clear','confirm'],
				done: function (value) {
				}
			});
		})
		let default_zhangqi =  $('input[name="start_date"]').val()
		if(default_zhangqi){
			console.log(default_zhangqi)

		}else{
			$('input[name="start_date"]').val(getStartDate()[0])
		}




		function getStartDate  (){
			// 15号以前 包含15 选次月
			//16还以后 包含16 选次次月

			var D = new Date();
			var  y, m, d;
			y = D.getFullYear();
			m = D.getMonth() + 1;
			d = D.getDate();
			var flag = false

			if(d<16){
				m+=1
			}else{
				m+=2;
				flag = true
			}

			if(m>12){
				y+=1
				m-=12
			}

			m = m > 9 ? m : '0' + m;

			var zhangqi = y + '-' + m


			let monthLastDay = new Date(y,m,0).getDate();
			var default_date =  y + '-' + m + '-' + '01';
			var end_date =  y + '-' + m + '-' + monthLastDay;

			var default_zhangqi =  $('input[name="start_date"]').val()
			if(default_zhangqi){
				var n1 = default_zhangqi.split("-");
				zhangqi =  n1[0] + '-' + n1[1]
				monthLastDay = new Date(n1[0],n1[1],0).getDate();
				default_date =  n1[0] + '-' + n1[1] + '-' + '01';
				end_date =  n1[0] + '-' + n1[1] + '-' + monthLastDay;
			}



			return [zhangqi,default_date,end_date,flag];

		}
		formSubmit = function (){
			var [e,f,g,h] = getStartDate()
			if(h){
				$.msg.confirm("账期是"+ e +",是否要提交？","提示" ,"tips", function (index) {
					$('form').submit()
					layer.close(index)
				});

			}else{

				$('form').submit()
			}


		}
		// 开关
		$('.weui-switch').click(function () {
			var p = $(this).parent().parent().parent()
			if($(this).is(":checked")){
				p.removeClass("notChange")
				p.find("[type!='checkbox']").removeAttr("disabled").attr("required","required")
			}else{
				p.addClass("notChange")
				p.find("[type!='checkbox']").val("").attr("disabled","disabled").removeAttr("required");
			}

		})
		// 工资变化 top
		$('[name="wage"]').on('change', function(){
			console.log($(this).val())
			$(".insurance_type div[class!='notChange']").find("[name^='insurance_wage']").val($(this).val())
			$.form.load('{:url("insuranceAllBase")}', {wage: $(this).val()}, "post", function (ret) {
				if (ret.code === 1) {
					var data = ret.data;
					for(i in data){

						$(".insurance_type div[class!='notChange']").find("[name='company_base["+ i +"]']").val(data[i].company)
						$(".insurance_type div[class!='notChange']").find("[name='personal_base["+ i +"]']").val(data[i].personal)
					}

				} else {
					$.msg.error(ret.info, 1)
				}
				return false;
			})
			form.render();
		})
		// 工资变化 bottom
		$("[name^='insurance_wage']").change(function(){
			var $par=$(this).parent().parent().parent('.insurance-box');
			var insurance= $par.attr("data-insurance");
			// console.log(insurance)
			if($(this).val()){
				$.form.load('{:url("insuranceBase")}', {wage: $(this).val(),insurance:insurance}, "post", function (ret) {
					if (ret.code === 1) {
						var data = ret.data;
						$("[name='company_base["+ insurance +"]']").val(data.company);
						$("[name='personal_base["+ insurance +"]']").val(data.personal)

					} else {
						$.msg.error(ret.info, 1)
					}
					return false;
				})
			}else{
				$("[name='company_base["+ insurance +"]']").val("");
				$("[name='personal_base["+ insurance +"]']").val("")
			}

		})
	})
</script>
<script>








</script>

{/block}
{block name="style"}
<style>
    .layui-table tbody tr:hover{
        background-color: #fff;
    }
</style>
{/block}


